#ifndef CCONFIGPARSER_H
#define CCONFIGPARSER_H

//#include "globalDef.h"
//#include "commDef.h"

#include <vector>

typedef struct CConfigItem {
    char szItemName[50];
    char szItemContent[500];
} CConfigItem, *LPConfigItem;

class CConfigParser
{
public:
    ~CConfigParser();
    static CConfigParser* getInstance()
    {
        if (nullptr == m_pInstance) {
            //锁
            if (nullptr == m_pInstance) {
                m_pInstance = new CConfigParser();
                static CConfigDestroy clConfigDestroy;
            }
            //放锁
        }
        return m_pInstance;
    }

    class CConfigDestroy {
    public:
        ~CConfigDestroy() {
            if (CConfigParser::m_pInstance) {
                delete CConfigParser::m_pInstance;
                CConfigParser::m_pInstance = nullptr;
            }
        }
    };

    bool load(const char* lpConfFile);
    const char* getString(const char* lpItemName);
    int getIntDefault(const char* lpItemName, const int iDefaultVal);
    bool getBoolDefault(const char* lpItemName, const int iDefaultVal);

private:
    CConfigParser();
    static CConfigParser* m_pInstance;
    std::vector<LPConfigItem> m_vecConfigItem;
};

#endif // CONFIGPARSER_H